'use client';

import type { messagesAiSummary } from '@/service/actions/message';
import { use, useState } from 'react';
import { Alert, AlertDescription, AlertTitle } from '../ui/alert';

export default function AiSummary({
  aiSummaryRes,
}: {
  aiSummaryRes: ReturnType<typeof messagesAiSummary>;
}) {
  const { result, error } = use(aiSummaryRes);
  const [show, setShow] = useState(!error);

  return show ? (
    <Alert className="absolute max-w-[500px] left-1/2 -translate-x-1/2 z-50 flex justify-between shadow-lg">
      <div>
        <AlertTitle>AI 消息总结</AlertTitle>
        <AlertDescription>{result}</AlertDescription>
      </div>
      <span
        className="i-ri-close-line hover:scale-110 transition-transform cursor-pointer shrink-0"
        onClick={() => setShow(false)}
      />
    </Alert>
  ) : null;
}
